package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IntegralDetails;
import com.ruoyi.system.service.IIntegralDetailsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工积分Controller
 * 
 * @author 503
 * @date 2021-05-04
 */
@Controller
@RequestMapping("/system/details")
public class IntegralDetailsController extends BaseController
{
    private String prefix = "system/details";

    @Autowired
    private IIntegralDetailsService integralDetailsService;

    @RequiresPermissions("system:details:view")
    @GetMapping()
    public String details()
    {
        return prefix + "/details";
    }

    /**
     * 查询员工积分列表
     */
    @RequiresPermissions("system:details:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IntegralDetails integralDetails)
    {
        startPage();
        List<IntegralDetails> list = integralDetailsService.selectIntegralDetailsList(integralDetails);
        return getDataTable(list);
    }

    /**
     * 导出员工积分列表
     */
    @RequiresPermissions("system:details:export")
    @Log(title = "员工积分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IntegralDetails integralDetails)
    {
        List<IntegralDetails> list = integralDetailsService.selectIntegralDetailsList(integralDetails);
        ExcelUtil<IntegralDetails> util = new ExcelUtil<IntegralDetails>(IntegralDetails.class);
        return util.exportExcel(list, "员工积分数据");
    }

    /**
     * 新增员工积分
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工积分
     */
    @RequiresPermissions("system:details:add")
    @Log(title = "员工积分", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IntegralDetails integralDetails)
    {
        return toAjax(integralDetailsService.insertIntegralDetails(integralDetails));
    }

    /**
     * 修改员工积分
     */
    @GetMapping("/edit/{integralId}")
    public String edit(@PathVariable("integralId") Long integralId, ModelMap mmap)
    {
        IntegralDetails integralDetails = integralDetailsService.selectIntegralDetailsById(integralId);
        mmap.put("integralDetails", integralDetails);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工积分
     */
    @RequiresPermissions("system:details:edit")
    @Log(title = "员工积分", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IntegralDetails integralDetails)
    {
        return toAjax(integralDetailsService.updateIntegralDetails(integralDetails));
    }

    /**
     * 删除员工积分
     */
    @RequiresPermissions("system:details:remove")
    @Log(title = "员工积分", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(integralDetailsService.deleteIntegralDetailsByIds(ids));
    }
}
